// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Algo_Alert

//@version=5
indicator(title="𝓢𝓾𝓹𝓮𝓻 𝓕𝓲𝓼𝓱𝓮𝓻 [Algo Alert]", format=format.price, precision=2)
period_ = input.int(17, title="Fair-value Period", minval=1)
leng = input.int(14, title="EMA Length", minval=1)
len = input.int(9, minval = 1, title = "Fisher Period")
green = input.color(#00ffbb, "Up Color") //#00ffbb
red = input.color(#ff1100, "Down Color") //#ff1100

barsback = period_/2 + 1
ma = ta.sma(close, period_)
dpo = close - ma[barsback]
sd = dpo / (ta.ema(high - low, period_)) * 100

src = sd
high_ = ta.highest(src, len)
low_ = ta.lowest(src, len)
round_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val
value = 0.0
value := round_(.66 * ((src - low_) / (high_ - low_) - .5) + .67 * nz(value[1]))
fish1 = 0.0
fish1 := .5 * math.log((1 + value) / (1 - value)) + .5 * nz(fish1[1])
fish2 = fish1[1]
//hline(1.5, "1.5", color=#E91E63)
//hline(0.75,"0.75", color=#787B86)
//hline(0, "0", color=#E91E63)
//hline(-0.75, "-0.75", color=#787B86)
//hline(-1.5, "-1.5", color=#E91E63)
w = plot(fish1, color=fish1>ta.ema(fish1, 3)?green:red, title="Fisher")
//plot(fish2, color=#FF6D00, title="Trigger")
q = plot(ta.ema(fish1, 3), color = color.white, display = display.none)
plot(ta.ema(fish1, leng), color = color.gray)

fill(w,q, fish1>ta.ema(fish1, 3)?color.new(green,80):color.new(red,80))

//plotchar(ta.crossover(fish1, ta.ema(fish1, 3)) ? fish1 : na, "Bull Mark", char = "o", location = location.absolute, color = green, size = size.tiny)
//plotchar(ta.crossunder(fish1, ta.ema(fish1, 3)) ? fish1 : na, "Bear Mark", char = "o", location = location.absolute, color = red, size = size.tiny)
//if ta.crossover(fish1, ta.ema(fish1, 3))
//    strategy.entry("l", strategy.long)
    
//if ta.crossunder(fish1, ta.ema(fish1, 3))
//    strategy.entry("s", strategy.short)